from django.db import models
# from erp.contact.models import Contact
# from erp.contact.models import Company
from erp.location.models import Location
import datetime

# Create your models here.
REP_CHOICES = (
    ('KA', 'Kyle Anderson'),
    ('JW', 'Jeff Weinkauf'),
    ('JD', 'Jason DeMoe'),
    ('JC', 'Jason Culp'),
    ('JS', 'Justin Sutter'),
	('JF', 'Joe Fritts'),
	('KB', 'Kelly Baum'),
	('SD', 'Steve Diamond'),
	('RP', 'Ray Priszner'),
	('JSH', 'Jim Shepard'),
)

class Customer(models.Model):
	name = models.CharField(maxlength=200)
	created = models.DateTimeField(editable=False)
	modified = models.DateTimeField(editable=False)
	slug = models.SlugField(prepopulate_from=("name",))
	
	def save(self):
		if not self.id:
			self.created = datetime.date.today()
		self.modified = datetime.datetime.today()
		super(Customer, self).save()
		
	def get_absolute_url(self):
		return "/%s/" % self.slug
	
	def __str__(self):
		return self.name
	
	class Admin:
		pass
		list_display = ('name',)
		search_fields = ['name']

class Note(models.Model):
	title = models.CharField('Note', maxlength=200)
	note = models.TextField('Additional Info', blank=True)
	author = models.CharField(maxlength=100, choices=REP_CHOICES)
	created = models.DateTimeField(editable=False)
	modified = models.DateTimeField(editable=False)
	slug = models.SlugField(prepopulate_from=("title",))
	
	def save(self):
		if not self.id:
			self.created = datetime.date.today()
		self.modified = datetime.datetime.today()
		super(Note, self).save()
		
	def get_absolute_url(self):
		return "/%s/" % self.slug
	
	def __str__(self):
		return self.title
	
	class Admin:
		pass
		list_display = ('title', 'note', 'author', 'created', 'modified')
		search_fields = ['title', 'note', 'author', 'created', 'modified']

class ReceivedItem(models.Model):
	item = models.CharField(maxlength=200, blank=True)
	rep = models.CharField(maxlength=100, choices=REP_CHOICES, blank=True)
	created = models.DateTimeField(editable=False)
	modified = models.DateTimeField(editable=False)
	note = models.ForeignKey(Note) #It would be nice to ty this into the notes model?
	# company = models.ForeignKey(Company, blank=True)
 	# contact = models.ForeignKey(Contact, blank=True)
	customer = models.ForeignKey(Customer)
	so_num = models.CharField('Sales Order Number', maxlength=100, blank=True)
	part_num = models.CharField('Part Number', maxlength=100, blank=True)
	slug = models.SlugField(prepopulate_from=("part_num",), blank=True)
	qty = models.IntegerField('Quantity', null=True, blank=True)
	po_num = models.CharField('Purchase Order Number', maxlength=100, blank=True)
	location = models.ForeignKey(Location)

	
	def save(self):
		if not self.id:
			self.created = datetime.date.today()
		self.modified = datetime.datetime.today()
		super(ReceivedItem, self).save()
		
	def get_absolute_url(self):
		return "/%s/" % self.slug
	
	def __str__(self):
		return self.item
	
	class Admin:
		pass
		list_display = ('created', 'customer', 'so_num', 'part_num', 'qty', 'po_num', 'location', 'rep', 'note')
		search_fields = ['title', 'note', 'author', 'created', 'modified']
		list_filter = ['created', 'rep']